#include<rtthread.h>
#include<rtdevice.h>

#if defined(BSP_USING_TSET)

#define DRV_DEBUG
#define LOG_TAG "drv.test"

#include<drv_log.h>

static rt_err_t dev_test_init(rt_device_t dev)
{
    LOG_I("test dev init");
    return RT_EOK;
}

static rt_err_t dev_test_open(rt_device_t dev,rt_uint16_t oflag)
{
    LOG_I("test dev init =%d",oflag);
    return RT_EOK;
}
static rt_err_t dev_test_close(rt_device_t dev)
{
    LOG_I("test dev close");
    return RT_EOK;
}
static rt_ssize_t dev_test_read(rt_device_t dev,rt_off_t pos,void *buffer,rt_size_t size)
{
    LOG_I("test dev read pos =%d ,size =%d",pos,size);
    return RT_EOK;
}
static rt_ssize_t dev_test_write(rt_device_t dev,rt_off_t pos,void *buffer,rt_size_t size)
{
     LOG_I("test dev write pos =%d ,size =%d",pos,size);
    return RT_EOK;
}
static rt_err_t dev_test_control(rt_device_t dev,int cmd,void *args)
{
    LOG_I("test dev contorl cmd %d",cmd);
    return RT_EOK;
}

int rt_drv_test_init(void)
{
  rt_device_t test_drv =rt_device_create(RT_Device_Class_Char,0);
    if(!test_drv)
    {
        LOG_E("test dev create failed.");
    }

    test_drv->init =dev_test_init;
    test_drv->open=dev_test_open;
    test_drv->close=dev_test_close;
    test_drv->read=dev_test_read;
    test_drv->write = dev_test_write;
    test_drv->control=dev_test_control;

    if (rt_device_register(test_drv,"test_drv",RT_DEVICE_FLAG_RDWR)!=RT_EOK)
    {
        LOG_E("test derv register failed.");
        return -RT_ERROR;
    }
    
    return RT_EOK;
}
INIT_BOARD_EXPORT(rt_drv_test_init);

#endif